package com.keiou.drink.ui.activity.base;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * 作者 ：Bob on 2017/10/10.
 * 邮箱 ：motherlovefather@126.com
 */

public abstract class RxActivity extends BaseActivity {
    protected CompositeSubscription mCompositeSubscription;


    /**
     * 将所有subscription放入,集中处理
     *
     * @param subscription
     */
    protected void addSubscribe(Subscription subscription) {
        if (null == mCompositeSubscription) {
            mCompositeSubscription = new CompositeSubscription();
        }
        mCompositeSubscription.add(subscription);
    }

    /**
     * 取消所有正在执行的订阅
     */
    public void unSubscribe() {
        if (null != mCompositeSubscription) {
            mCompositeSubscription.unsubscribe();
        }
    }

    @Override
    protected void onDestroy() {
        unSubscribe();
        super.onDestroy();
    }
}
